﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfApp.Controls
{
    /// <summary>
    /// PropertyControl.xaml 的交互逻辑
    /// </summary>
    public partial class PropertyControl : UserControl
    {
        public PropertyControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
        /// <summary>
        /// 不能将值反馈到主界面的ViewModel
        /// </summary>
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(PropertyControl), new PropertyMetadata(""));



        public int Count
        {
            get { return (int)GetValue(CountProperty); }
            set { SetValue(CountProperty, value); }
        }
        /// <summary>
        /// 可将值反馈到主界面的ViewModel
        /// </summary>
        public static readonly DependencyProperty CountProperty =
            DependencyProperty.Register("Count", typeof(int), typeof(PropertyControl), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Count++;
        }

        private void BtnTitleChange_Click(object sender, RoutedEventArgs e)
        {
            Random random = new Random();
            Title += random.Next(1, 9);
        }
    }
}
